package com.youyou.fusheng2.View.Adapter;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.youyou.fusheng2.Moudle.OnClick2;
import com.youyou.fusheng2.R;

import java.util.List;
import java.util.Map;

/**
 * @name fusheng2
 * @class name：com.youyou.fusheng2.View.Adapter
 * @anthor 浮生 QQ:2567294605
 * @time 2020/8/26 15:43
 * @to
 */
public class SouSuoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<Map<String, String>>             sousuoList;
    private com.youyou.fusheng2.Moudle.sousuoShow sousuoShow;
    private OnClick2 onClick2;

    public void setSousuoList(List<Map<String, String>> sousuoList) {
        if (sousuoList.isEmpty()) {
            sousuoShow.showTextView(true);
        } else {
            sousuoShow.showTextView(false);
            this.sousuoList = sousuoList;
        }
    }

    public SouSuoAdapter(com.youyou.fusheng2.Moudle.sousuoShow sousuoShow,OnClick2 onClick2) {
        this.sousuoShow = sousuoShow;
        this.onClick2=onClick2;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.sousuoitem, parent, false);
        return new SouSuoItem(inflate);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        Glide.with(holder.itemView.getContext())
                .load(sousuoList.get(position).get("pic"))
                .into(((SouSuoItem) holder).sousuo_image);
        ((SouSuoItem) holder).sousuo_fen.setText("清晰度:  " + sousuoList.get(position).get("note"));
        ((SouSuoItem) holder).sousuo_name.setText("影名:  " + sousuoList.get(position).get("name"));
        ((SouSuoItem) holder).sousuo_hd.setText("评分:  " + sousuoList.get(position).get("score"));
        ((SouSuoItem) holder).sousuo_play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClick2.listener1(0,sousuoList.get(position).get("tid"));
            }
        });
    }

    @Override
    public int getItemCount() {
        return sousuoList == null ? 0 : sousuoList.size();
    }

    private static class SouSuoItem extends RecyclerView.ViewHolder {

        private ImageView sousuo_image;
        private TextView  sousuo_fen;
        private TextView  sousuo_name;
        private TextView  sousuo_hd;
        private Button    sousuo_play;

        public SouSuoItem(View inflate) {
            super(inflate);
            sousuo_image = inflate.findViewById(R.id.sousuo_image);
            sousuo_fen = inflate.findViewById(R.id.sousuo_fen);
            sousuo_name = inflate.findViewById(R.id.sousuo_name);
            sousuo_hd = inflate.findViewById(R.id.sousuo_hd);
            sousuo_play = inflate.findViewById(R.id.sousuo_play);

        }
    }
}
